local UIBase = require("view.UIBase")
local PopupInviteTeamGroup = class("PopupInviteTeamGroup", UIBase)

function PopupInviteTeamGroup:ctor(teamId, user, targetId, callback)
    self._teamId = teamId
    self._user = user
    self._targetId = targetId
    self._callback = callback
    local resource = {
        path = "Prefabs/View/TeamGroup",
        name = "PopupInviteTeamGroup",
        canvas = 3
    }
    PopupInviteTeamGroup.super.ctor(self, resource)
end

function PopupInviteTeamGroup:start()
    local cfg = require("config.monsterhole").get(self._targetId)
    self._textCount.text = Lang.get("lang_team_group_invite_tips", {name = self._user.userName, targetName = cfg.name})
    self._btnOk.onClick:AddListener(handler(self, self._onBtnOkClick))
    self._btnrRefuse.onClick:AddListener(handler(self, self._onBtnRefuseClick))
end

function PopupInviteTeamGroup:onClose()
    if self._callback then
        self._callback()
    end
end

function PopupInviteTeamGroup:_onBtnOkClick()
    self:close()
    G_UserData:getTeamGroup():c2sOptInviteTeam(self._teamId, 1)
end

function PopupInviteTeamGroup:_onBtnRefuseClick()
    self:close()
    G_UserData:getTeamGroup():c2sOptInviteTeam(self._teamId, 2)
end

return PopupInviteTeamGroup
